<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <p>{{name}}</p>
        <p>{{obj}}</p>
        <my-book :name="name" :obj="obj"></my-book>

    </div>

    <script>
        Vue.component("my-book", {
            props: ["name","obj" ],
            data(){
                return {
                    myName:this.name
                }
            },
            template: `
            <div>
                <p>{{name}}</p>
                <button @click="name='水浒传'">改下试试</button>

                <p>修改自有属性（初始值为prop）：{{myName}}</p>
                <button @click="myName='水浒传'">改变自由属性</button>
                
                <p>传入的对象：{{obj}}</p>
                <button @click="obj.name='西游记'">修改传入对象的name属性</button>
            </div>            
            `
        })

        var app = new Vue({
            el: "#app",
            data: {
                name: "西游记",
                obj:{
                    name:"小明",
                    age:18
                }
            }
        });

    </script>
</body>

</html>